package ysq.xyg.base.extend.activemq.service;

import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

/**
 * 队列生产者
 *
 * @author shengQiang yu
 * @date 2019-05-24 11:24
 */
@Component
public class ProducerService {

    @Resource
    private JmsTemplate jmsTemplate;

    public void sendMsg(Destination destination, final String content){
        jmsTemplate.send(destination, new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                return session.createTextMessage(content);
            }
        });
    }


}
